package offer.diff;

import java.util.Arrays;

/**
 * @author DengYuan2
 * @create 2021-03-23 19:32
 */
public class n_56 {
    public static void main(String[] args) {
        n_56 n = new n_56();
        int[] array ={1,4,1,6};
        int[] res = n.FindNumsAppearOnce(array);
        System.out.println(Arrays.toString(res));
    }

    public int[] FindNumsAppearOnce (int[] nums) {

        int[] res = new int[2];
        int diff = 0;
        for (int num : nums){
            diff ^= num;
        }
        diff &= -diff;
        for (int num : nums) {
            if ((num & diff) == 0)
                res[0] ^= num;
            else
                res[1] ^= num;
        }
        if (res[0] > res[1]) {
            swap(res);
        }
        return res;
    }

    private void swap(int[] nums) {
        int t = nums[0];
        nums[0] = nums[1];
        nums[1] = t;
    }

}
